/*
 * Histogram2.h
 *
 *  Created on: 21.03.2013
 *      Author: mag
 */

#ifndef BACKEND_HISTOGRAM2_H_
#define BACKEND_HISTOGRAM2_H_

#include "TimeTagger.h"

/**
 * create autocorrelated histogram of channel events
 */
class Histogram2 : public _Iterator {

public:
	static const int STD_BUFFERSIZE=4096;
	static const int STD_TIMESPAN=4096;
	static const int STD_BINWIDTH=4096;

	Histogram2(int chan1,							// channel config
				  int chan2 = -1,
			      long long _binwidth=STD_BINWIDTH,		// max timediff
			      long long _timespan=STD_TIMESPAN,		// time intervall
			      unsigned _buffer_size=STD_BUFFERSIZE );

	virtual ~Histogram2();

	virtual const char *getClassName();
	virtual const char * getScpiCommand();
	virtual std::string getScpiParameters();

	/**
	 * get module meta data as array of longs..
	 * format:
	 * 		[0] channel1
	 * 		[1] channel2
	 * 		[2] binwidth
	 * 		[3] timespan
	 * 		[4] total click count
	 * 		[5] channel1 click count
	 * 		[6] channel2 click count
	 * 		[7] duration
	 * 		[8] time of first click
	 * 		[9] time of last click
	 */
	void getMeta(long long **ARGOUTVIEWM_ARRAY2, int *DIM1);

	/**
	 * get measurement result as 2dimensional long array.
	 * format:
	 *   [tm][0] - time window
	 *   [tm][1] - squared autocorrelated counts
	 *   [tm][2] - scaled autocorrelated counts  ???
	 *   [tm][3] - autocorrelated channel2 clicks ???
	 *
	 */
	void getData(long long **ARGOUTVIEWM_ARRAY2, int *DIM1, int *DIM2);


	virtual void clear();

	void clear_buffer();

	virtual void next(Tag* tag, int count, long long time);

protected:

	int channel1, channel2;
	long long binwidth;
	long long timespan;
	unsigned buffer_size;

	long long first_time, last_time;
	long long ch1_count, ch2_count;
	long long *ch1_buffer, *ch2_buffer;
	long long *histogram1, *histogram2;

};


#endif /* HISTOGRAM2_H_ */
